checkNullToString(value) {
  return value != null ? value.toString() : '';
}

class LocationData {
  LocationData({
    this.latitude,
    this.longitude,
    this.time,
    this.city,
    this.country,
    this.district,
    this.info,
    this.address,
  });

  static fromMap(Map dataMap) {
    return LocationData(
      latitude: double.tryParse(checkNullToString(dataMap['latitude'])),
      longitude: double.tryParse(checkNullToString(dataMap['longitude'])),
      time: checkNullToString(dataMap['callbackTime']),
      city: checkNullToString(dataMap['city']),
      district: checkNullToString(dataMap['district']),
      country: checkNullToString(dataMap['country']),
      address:
          '${checkNullToString(dataMap['city'])}${checkNullToString(dataMap['district'])}',
      info: dataMap,
    );
  }

  final Map info;

  /// Latitude in degrees
  final double latitude;

  /// Longitude, in degrees
  final double longitude;

  /// timestamp of the LocationData
  final String time;

  final String city;

  final String country;

  final String district;

  final String address;
  @override
  String toString() => info.toString();

  @override
  bool operator ==(Object other) =>
      identical(this, other) ||
      other is LocationData &&
          runtimeType == other.runtimeType &&
          latitude == other.latitude &&
          longitude == other.longitude &&
          time == other.time;

  @override
  int get hashCode => latitude.hashCode ^ longitude.hashCode ^ time.hashCode;
}
